package com.qiangesoft.design.structural.proxy.staticp;

/**
 * 静态代理
 */
public class StaticProxy {
    public static void main(String[] args) {
        Driver driver = new ProxyDriver(new RealDriver());
        driver.drive("奥迪A4L");
    }
}

/**
 * 驾驶员接口
 */
interface Driver {
    void drive(String car);
}

/**
 * 真实驾驶员
 */
class RealDriver implements Driver {

    @Override
    public void drive(String car) {
        System.out.println("【" + car + "】被开回家了");
    }
}

/**
 * 代理驾驶员
 */
class ProxyDriver implements Driver {

    private RealDriver realDriver;

    public ProxyDriver(RealDriver realDriver) {
        this.realDriver = realDriver;
    }

    @Override
    public void drive(String car) {
        System.out.println("代驾取钥匙");
        realDriver.drive(car);
        System.out.println("代驾还钥匙");
    }
}